<!doctype html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>配送员工作台</title>
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--<meta name="format-detection" content="telephone = no" />-->
    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="发货中"/>
    <meta name="msapplication-TileColor" content="#090a0a">
    <link rel="stylesheet" href="{{asset('myhome/css/css_styllle.css')}}">
    <link rel="stylesheet" href="{{ asset('myhome/css/headerl.css') }}">
    <link rel="stylesheet" href="{{ asset('myhome/css/font.css') }}">

    <style>
        .zt {
            float: right!important;
            color: white!important;
            height: 30px!important;
            width: 150px!important;
            background-color: rgba(233, 104, 98, 0.95)!important;
            border-radius: 5px!important;
            text-align: center!important;
            line-height: 30px!important;
            margin-right: 1.8rem!important;
        }

        .zt_a {
            float: right;
            background-color: #888888;
            height: 30px;
            width: 150px;
            border-radius: 5px;
            text-align: center;
            line-height: 30px;
            margin-right: 1.8rem;
        }

        .zt_b {
            color: white!important;
            float: right!important;
            background-color: #2cb6b4!important;
            height: 30px!important;
            width: 150px!important;
            border-radius: 5px!important;
            text-align: center!important;
            line-height: 30px!important;
            margin-right: 1.8rem!important;
        }
    </style>
    <script type="text/javascript" src="{{asset('js/zepto.min.js')}}"></script>

</head>
<body class='grayBy'>
<header>
    <div class="header">
        <h1>配送员工作台</h1>
        <a href="/home/user" class="return">&lt;</a>

    </div>
</header>
<div style="margin-top: 60px;"></div>
<div id="did">


</div>
<div class="footer_fixed clearfix">
    <span><a href="{{ asset('sender/index') }}"><i class="home_icon"></i><b>首页</b></a></span>
    <span><a href="{{ asset('sender/info') }}"><i class="member_icon"></i><b>我的</b></a></span>
</div>
</body>
</html>
<script type="text/javascript">
    var str = " ";
    redata();
    setInterval(redata, 10000)
    //请求新订单数据
    function redata() {

        $.ajax({
            url: '{{url("sender/redata")}}',
            type: 'POST',
            async: false,
            dataType: 'json',
            //cache: false,
            data: {_token: "{{ csrf_token() }}"},

            success: function (data) {
                var str = "";
                for (var i = 0; i < data.length; i++) {
                    //转换时间戳
                    var iclass="";
                    var ts="";
                    var time = [];
                    var date = data[i].order.pay_at;
                    date = date.replace(/-/g, '/');
                    time = new Date(date).getTime();
                    var ntime = new Date().getTime();
                    var stime = 40 - Math.round((ntime - time) / 60000);
                    var ltime = stime + '分钟';
                    if (stime < 0) {
                        ltime = "已超时";
                    }
                    if (data[i].order.status == 2) {
                        iclass="zt";
                        ts='立即配送';
                    }else{
                        iclass="zt_b";
                        ts='完成配送';
                    }
                    //alert(ltime);
                    str = str + "<div class='order_box'> <div class='order_header'> <h2>订单编号: " + data[i].order.number + "</h2> <h3>收&nbsp;货&nbsp;人&nbsp;: <a>" + data[i].order.name + "</a>    </h3>  <h3>收货地址: <a >" + data[i].order.address + "</a></h3> <h3>配送时间:<a>2016-12-27 10:35</a>       &nbsp;&nbsp;&nbsp; 剩余时间<a> " + ltime + "</a></h3> <span class='up_icon'></span> <h3></li></a><li class='"+iclass+"' id='zt'  onclick='chstu("+data[i].order.status+","+data[i].order.id+")'>"+ts+"</li><a href='tel:" + data[i].order.phone + "'><li  class='zt' class='icon-tel' >联系顾客</li></a></h3></div>";
                    for (var j = 0; j < data[i].order_info.length; j++) {
                        str = str + " <ul class='order_list'> <li> <a href=''> <i class='pic'><img src='/upload/product/" + data[i].order_info[j].preview + "'/></i> <h2>" + data[i].order_info[j].name + "</h2> <h3>规格<span>" + data[i].order_info[j].specifications + "</span></h3> <h4> X" + data[i].order_info[j].count + "</h4> <b>" + data[i].order_info[j].price + "元</b> </a> </li> </ul>";
                    }
                    str = str + "</div>";

                }
                var tip = $(str);
                $("#did").html(tip);
                $(".order_box").click(function () {
                    $(this).find(".order_list").toggle();
                });

            },
            error: function (data) {
            }
        });
    }
    function chstu(a,id) {
            $("#zt").attr('class','zt_b');
            $.ajax({
                url: '{{url("sender/chstu")}}',
                type: 'POST',
                async: false,
                dataType: 'json',
                //cache: false,
                data: {_token: "{{ csrf_token() }}",action:a,id:id},

                success: function (data) {
                    if(data==2 ){
                       redata();
                       alert("请在四十分钟内送达！");
                    }else if(data==4){
                        redata();
                        alert("完成送达，可在个人中心查看历史派单！");
                    }
                },
            });

    }

    //redata();

</script>